/**
 * 模拟数组

includes方法
 * @param {array} arr
 * @param {*} searchElement
 * @param {number} - 搜寻起始下标
 * @return {boolean}
 */
export default function includes<T>(
  arr: T[],
  searchElement: T,
  fromIndex?: number
): boolean {
  const length: number = arr.length;
  if (fromIndex && fromIndex >= length) return false;
  let startIndex: number = 0;
  if (fromIndex) {
    if (fromIndex >= 0) {
      startIndex = fromIndex;
    } else {
      if (fromIndex + length < 0) {
        startIndex = 0;
      } else {
        startIndex = fromIndex + length;
      }
    }
  }

  let i: number = startIndex;

  for (; i < length; ++i) {
    if (arr[i] === searchElement) return true;
  }
  return false;
}